--- title: 'Week 6: The Ground Game ' author: Janet Hernandez date: '2022-10-16' slug: [] categories: - R - Polling - national - local - Economy - incumbancy - ads tags: - plot - regression type: '' subtitle: 'This week I will be looking at how the Ground Game or ' image: '' ---
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ dplyr   1.0.10
## ✔ tibble  3.1.8      ✔ stringr 1.4.1 
## ✔ tidyr   1.2.1      ✔ forcats 0.5.2 
## ✔ purrr   0.3.4      
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## 
## Attaching package: 'scales'
## 
## 
## The following object is masked from 'package:purrr':
## 
##     discard
## 
## 
## The following object is masked from 'package:readr':
## 
##     col_factor
## 
## 
## 
## Attaching package: 'plotly'
## 
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## 
## The following object is masked from 'package:graphics':
## 
##     layout
## 
## 
## Loading required package: gsubfn
## 
## Loading required package: proto
## 
## tcltk DLL is linked to '/opt/X11/lib/libX11.6.dylib'
## 
## Could not load tcltk.  Will use slower R code instead.
## 
## Loading required package: RSQLite
## 
## Rows: 16067 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): Office, State, Area, RepCandidate, RepStatus, DemCandidate, DemSta...
## dbl (14): raceYear, RepVotes, DemVotes, ThirdVotes, OtherVotes, PluralityVot...
## lgl  (1): CensusPop
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 16067 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): Office, State, Area, RepCandidate, RepStatus, DemCandidate, DemSta...
## dbl (14): raceYear, RepVotes, DemVotes, ThirdVotes, OtherVotes, PluralityVot...
## lgl  (1): CensusPop
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 16067 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): Office, State, Area, RepCandidate, RepStatus, DemCandidate, DemSta...
## dbl (14): raceYear, RepVotes, DemVotes, ThirdVotes, OtherVotes, PluralityVot...
## lgl  (1): CensusPop
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## 
## 1948 1950 1952 1954 1956 1958 1960 1962 1964 1966 1968 1970 1972 1974 1976 1978 
##  433  433  433  433  433  433  435  426  433  433  434  435  435  435  435  435 
## 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 
##  435  435  435  435  435  435  435  435  437  435  435  436  437  436  435  421 
## 2012 2014 2016 2018 2020 
##  436  436  437  436  436
## 
##  101  102  103  104  105  106  107  200  401  402  403  404  405  406  407  408 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  409  501  502  503  504  601  602  603  604  605  606  607  608  609  610  611 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  612  613  614  615  616  617  618  619  620  621  622  623  624  625  626  627 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  628  629  630  631  632  633  634  635  636  637  638  639  640  641  642  643 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  644  645  646  647  648  649  650  651  652  653  801  802  803  804  805  806 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
##  807  901  902  903  904  905 1000 1201 1202 1203 1204 1205 1206 1207 1208 1209 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1226 1227 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1501 1502 1601 1602 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1713 1714 1715 1716 1717 1718 1801 1802 1803 1804 1805 1806 1807 1808 1809 1901 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1902 1903 1904 2001 2002 2003 2004 2101 2102 2103 2104 2105 2106 2201 2202 2203 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2204 2205 2206 2301 2302 2401 2402 2403 2404 2405 2406 2407 2408 2501 2502 2503 
##    1    1    1    1    2    1    1    1    1    1    1    1    1    1    1    1 
## 2504 2505 2506 2507 2508 2509 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2611 2612 2613 2614 2701 2702 2703 2704 2705 2706 2707 2708 2801 2802 2803 2804 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2901 2902 2903 2904 2905 2906 2907 2908 3000 3101 3102 3103 3201 3202 3203 3204 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 3301 3302 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3501 3502 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 3503 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3701 3702 3703 3704 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 3705 3706 3707 3708 3709 3710 3711 3712 3713 3800 3901 3902 3903 3904 3905 3906 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 4001 4002 4003 4004 4005 4101 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4102 4103 4104 4105 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4213 4214 4215 4216 4217 4218 4401 4402 4501 4502 4503 4504 4505 4506 4507 4600 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4701 4702 4703 4704 4705 4706 4707 4708 4709 4801 4802 4803 4804 4805 4806 4807 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4901 4902 4903 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 4904 5000 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5301 5302 5303 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 5304 5305 5306 5307 5308 5309 5310 5401 5402 5403 5501 5502 5503 5504 5505 5506 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 5507 5508 5600 
##    1    1    1

Note that 2018 in comparison to the model in lab that included more years has a greater correlation it seems of voter turnout and democratic major vote pct.

## 
## Call:
## lm(formula = DemVotesMajorPercent ~ turnout, data = dist_pv_cvap_closed)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -34.060 -12.411  -2.361  11.883  45.749 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   46.623      5.607   8.314 1.52e-15 ***
## turnout       11.132     11.075   1.005    0.315    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.4 on 393 degrees of freedom
## Multiple R-squared:  0.002564,   Adjusted R-squared:  2.583e-05 
## F-statistic:  1.01 on 1 and 393 DF,  p-value: 0.3155
## 
## Call:
## glm(formula = DemVotesMajorPct ~ turnout, family = binomial(link = "logit"), 
##     data = dist_pv_cvap_closed)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -0.70849  -0.24881  -0.04725   0.23968   1.02030  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.1355     0.6847  -0.198    0.843
## turnout       0.4462     1.3528   0.330    0.741
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 44.956  on 394  degrees of freedom
## Residual deviance: 44.847  on 393  degrees of freedom
## AIC: 551.77
## 
## Number of Fisher Scoring iterations: 3

Adding voter turnout into my predictive model to see how it might affect my results.

Observations 1308
Dependent variable turnout
Type OLS linear regression
F(53,1254) 51.97
0.69
Adj. R² 0.67
Est. S.E. t val. p
(Intercept) 183.77 5.01 36.69 0.00
year -0.09 0.00 -36.70 0.00
state.xAlaska 0.08 0.05 1.82 0.07
state.xArizona -0.04 0.02 -1.70 0.09
state.xArkansas -0.05 0.03 -1.99 0.05
state.xCalifornia 0.01 0.02 0.57 0.57
state.xColorado 0.09 0.02 4.00 0.00
state.xConnecticut 0.08 0.02 3.26 0.00
state.xDelaware -0.13 0.05 -2.75 0.01
state.xFlorida -0.02 0.02 -0.84 0.40
state.xGeorgia 0.03 0.02 1.53 0.13
state.xHawaii -0.03 0.03 -0.94 0.34
state.xIdaho -0.03 0.03 -0.87 0.39
state.xIllinois 0.07 0.02 3.95 0.00
state.xIndiana -0.02 0.02 -1.16 0.25
state.xIowa 0.09 0.03 3.30 0.00
state.xKansas 0.04 0.03 1.32 0.19
state.xKentucky 0.02 0.02 0.70 0.48
state.xLouisiana -0.13 0.02 -5.48 0.00
state.xMaine 0.13 0.03 4.10 0.00
state.xMaryland 0.07 0.02 3.35 0.00
state.xMassachusetts 0.02 0.02 1.16 0.25
state.xMichigan 0.08 0.02 4.01 0.00
state.xMinnesota 0.19 0.02 8.69 0.00
state.xMississippi -0.07 0.03 -2.59 0.01
state.xMissouri -0.01 0.02 -0.26 0.79
state.xMontana -0.14 0.05 -2.85 0.00
state.xNebraska 0.13 0.03 4.51 0.00
state.xNevada -0.00 0.03 -0.07 0.95
state.xNew Hampshire 0.11 0.03 3.28 0.00
state.xNew Jersey 0.03 0.02 1.37 0.17
state.xNew Mexico 0.04 0.03 1.34 0.18
state.xNew York -0.03 0.02 -1.40 0.16
state.xNorth Carolina 0.02 0.02 1.08 0.28
state.xNorth Dakota 0.04 0.05 0.90 0.37
state.xOhio 0.03 0.02 1.30 0.19
state.xOklahoma -0.10 0.02 -3.87 0.00
state.xOregon 0.04 0.03 1.65 0.10
state.xPennsylvania 0.03 0.02 1.73 0.08
state.xRhode Island 0.15 0.03 4.44 0.00
state.xSouth Carolina -0.02 0.02 -0.88 0.38
state.xSouth Dakota -0.02 0.05 -0.39 0.70
state.xTennessee -0.07 0.02 -3.23 0.00
state.xTexas -0.04 0.02 -2.03 0.04
state.xUtah 0.02 0.03 0.89 0.37
state.xVermont 0.09 0.05 2.02 0.04
state.xVirginia 0.04 0.02 2.05 0.04
state.xWashington 0.09 0.02 4.16 0.00
state.xWest Virginia -0.01 0.03 -0.17 0.86
state.xWisconsin 0.15 0.02 7.03 0.00
state.xWyoming 0.10 0.05 2.14 0.03
president_partyR 0.52 0.01 39.68 0.00
cvap 0.00 0.00 15.55 0.00
winner_candidate_incIncumbent -0.01 0.01 -2.16 0.03
Standard errors: OLS

Plotting differences in margin for turnout to test the accuracy of my prediction variable for 2022 turnout to add to my model later. Red indicates that the actual value is less than predicted value, therefore my model is under predicting in the red areas. The same goes for the blue. Where its more blue, such as in Florida, the predictive model is having a hard time and is over predicting these areas for voter turnout.